﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebControls;
using System.Drawing;


namespace SharePoint.Extensions.MOSSAnalytics
{
    public class GetUniqueUsersByDayWebPart : WebPart
    {
        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            base.RenderContents(writer);
            this.EnsureChildControls();
        }

        protected override void CreateChildControls()
        {
            try
            {
                GetUniqueUsersByDay uniqueusers = new GetUniqueUsersByDay();
                DataTable dtUniqueUsers = uniqueusers.GetData();

                SPGridView gvUniqueUsers = new SPGridView();
                gvUniqueUsers.AutoGenerateColumns = false;

                gvUniqueUsers.Columns.Add(Common.CreateBoundField("FullDate", "Date"));
                gvUniqueUsers.Columns.Add(Common.CreateBoundField("UniqueUsers", "# of unique users"));
                               

                gvUniqueUsers.DataSource = dtUniqueUsers;
                gvUniqueUsers.DataBind();

                this.Controls.Add(gvUniqueUsers);
            }
            catch (Exception ex)
            {
                Label lblError = new Label();
                lblError.Text = ex.ToString();
                lblError.ForeColor = Color.Red;

                this.Controls.Add(lblError);
            }
        }
    }
}
